package com.javajun.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.javajun.entity.Admin;

/**
 * @ClassName: SessionInterceptor
 * @Description: 拦截器，如果获取不到指定的session，则跳转到登录页面
 * @author: xlm
 * @date: 2018年10月15日
 */
public class SessionInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Admin admin = (Admin) request.getSession().getAttribute("user");
		if(admin == null) {
			response.sendRedirect(request.getContextPath());
			return false;
		}
		return super.preHandle(request, response, handler);
	}

}
